package main.java;

/**
 * @program: pratice
 * @author: 关键我是大怪
 * @create: 2021-08-23 17:46
 */
public class Test11_快速排序算法 {

    public static void test(int a[], int begin, int end) {
        if (begin < end) {
            int l = begin;
            int r = end;
            int temp = a[begin];
            while (l < r) {
                while (l < r && a[r] > temp) {
                    r--;
                }
                if (l < r) {
                    a[l] = a[r];
                }
                while (l < r && a[l] <= temp) {
                    l++;
                }
                if (l < r) {
                    a[r] = a[l];
                }

            }
            a[l] = temp;
            test(a, begin, l - 1);
            test(a, l + 1, end);
        }
    }


    public static void main(String[] args) {
        int num[] = {12, 43, 23, 55, 74, 23, 51};
        test(num, 0, num.length - 1);
        for (int i : num) {
            System.out.println(i);
        }
    }
}